import 'dart:async';

import 'package:flutter/material.dart';

class JMDebounce {
  JMDebounce({this.delay = const Duration(milliseconds: 500)});

  Duration delay;

  Timer? _timer;

  call(VoidCallback callback) {
    _timer?.cancel();
    _timer = Timer(delay, callback);
  }

  bool get isRunning => _timer?.isActive ?? false;

  void cancel() => _timer?.cancel();
}
